Before your application can work with a movie, you must load the movie from its file. You must open the movie file and create a new movie from the movie stored in the file. You can then work with the movie. You use the OpenMovieFile function to open a movie file and the NewMovieFromFile function to load a movie from a movie file. The code in Example 0.2 shows how you can use these functions.
Movie GetMovie (void)
{
OSErr err;
SFTypeList typeList = {MovieFileType,0,0,0};
StandardFileReply reply;
Movie aMovie = nil;
short movieResFile;
StandardGetFilePreview (nil, 1, typeList, &reply);
if (reply.sfGood)
{
err = OpenMovieFile (&reply.sfFile, &movieResFile,
fsRdPerm);
if (err == noErr)
{
short movieResID = 0; /* want first movie */
Str255 movieName;
Boolean wasChanged;
err = NewMovieFromFile (&aMovie, movieResFile,
&movieResID,
movieName,
newMovieActive, /* flags */
&wasChanged);
CloseMovieFile (movieResFile);
}
}
return aMovie;
}
The QuickTime Movie Toolbox uses Alias Manager and File Manager functions to manage a movie's references to its data. A movie file does not necessarily contain the movie's data. The movie's data may reside in other files, which are referred to by the movie file. When your application instructs the Movie Toolbox to play a movie, the Toolbox attempts to collect the movie's data. If the movie has become separated from its data, the Movie Toolbox uses the Alias Manager to locate the data files. During this search, the Movie Toolbox automatically displays a dialog box. The user can cancel the search by clicking the Stop button.
The code in Example 0.3 shows the steps your application must follow in order to play a movie. This program retrieves a movie, sizes the window properly, plays the movie forward, and exits. This program uses the GetMovie function shown in Example 0.2 to retrieve a movie from a movie file.
#include <Types.h>
#include <Traps.h>
#include <Menus.h>
#include <Fonts.h>
#include <Packages.h>
#include <GestaltEqu.h>
#include "Movies.h"
#include "ImageCompression.h"
/* #include "QuickTimeComponents.h" */
#define doTheRightThing 5000
void main (void)
{
WindowPtr aWindow;
Rect windowRect;
Rect movieBox;
Movie aMovie;
Boolean done = false;
OSErr err;
EventRecord theEvent;
WindowPtr whichWindow;
short part;
InitGraf (&qd.thePort);
InitFonts ();
InitWindows ();
InitMenus ();
TEInit ();
InitDialogs (nil);
err = EnterMovies ();
if (err) return;
SetRect (&windowRect, 100, 100, 200, 200);
aWindow = NewCWindow (nil, &windowRect, "\pMovie",
false, noGrowDocProc, (WindowPtr)-1,
true, 0);
SetPort (aWindow);
aMovie = GetMovie ();
if (aMovie == nil) return;
GetMovieBox (aMovie, &movieBox);
OffsetRect (&movieBox, -movieBox.left, -movieBox.top);
SetMovieBox (aMovie, &movieBox);
SizeWindow (aWindow, movieBox.right, movieBox.bottom, true);
ShowWindow (aWindow);
SetMovieGWorld (aMovie, (CGrafPtr)aWindow, nil);
StartMovie (aMovie);
while ( !IsMovieDone(aMovie) && !done )
{
if (WaitNextEvent (everyEvent, &theEvent, 0, nil))
{
switch ( theEvent.what )
{
case updateEvt:
whichWindow = (WindowPtr)theEvent.message;
if (whichWindow == aWindow)
{
BeginUpdate (whichWindow);
UpdateMovie(aMovie);
SetPort (whichWindow);
EraseRect (&whichWindow->portRect);
EndUpdate (whichWindow);
}
break;
case mouseDown:
part = FindWindow (theEvent.where,
&whichWindow);
if (whichWindow == aWindow)
{
switch (part)
{
case inGoAway:
done = TrackGoAway (whichWindow,
theEvent.where);
break;
case inDrag:
DragWindow (whichWindow,
theEvent.where,
&qd.screenBits.bounds);
break;
}
}
break;
}
}
MoviesTask (aMovie, DoTheRightThing);
}
DisposeMovie (aMovie);
DisposeWindow (aWindow);
}
| Previous | Chapter Top | Next |